#include <Client.h>
#include <iostream>
#include <sign_kernel.h>

Client::Client(/* args */)
    : port(8080), ip("127.0.0.1")
{
    Socket::CreatSocket(AF_INET, SOCK_STREAM);
}

Client::Client(const int port, const char *ip)
    : port(port), ip(ip)
{
    Socket::CreatSocket(AF_INET, SOCK_STREAM);
}

Client::Client(const int port, const char *ip, enum __socket_type type)
    : port(port), ip(ip)
{
    Socket::CreatSocket(AF_INET, type);
}

Client::~Client()
{
    Socket::CloseSocket();
}

int Client::Connect(void)
{
    struct sockaddr_in server_address;
    bzero(&server_address, sizeof(server_address));
    server_address.sin_family = AF_INET;
    server_address.sin_port = htons(port);
    server_address.sin_addr.s_addr = inet_addr(ip);
    Socket::Connect(&server_address, sizeof(server_address));
}

ssize_t Client::Read(void *buf, size_t count)
{
    Socket::Read(sockfd, buf, count);
}

ssize_t Client::Readn(void *buf, size_t count)
{
    Socket::Readn(sockfd, buf, count);
}

ssize_t Client::Readline(void *buf)
{
    Socket::Readline(sockfd, buf);
}

ssize_t Client::Write(const void *buf, size_t count)
{
    Socket::Write(sockfd, buf, count);
}

ssize_t Client::Writen(const void *buf, size_t count)
{
    Socket::Writen(sockfd, buf, count);
}

ssize_t Client::Send(const void *__buf, size_t __n, int __flags)
{
    Socket::Send(sockfd, __buf, __n, __flags);
}

ssize_t Client::Recv(void *__buf, size_t __n, int __flags)
{
    Socket::Recv(sockfd, __buf, __n, __flags);
}